package com.itheima.project_cloth.controller;

import com.itheima.project_cloth.pojo.Consumer;
import com.itheima.project_cloth.pojo.Result;
import com.itheima.project_cloth.service.ConsumerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/consumes")
public class ConsumerController {
    @Autowired
    private ConsumerService consumerService;


    @GetMapping("/{vipStatus}")
    public Result SelectConsumerByVip(@PathVariable Integer vipStatus){
        log.info("根据vip查询消费者信息 {}",vipStatus);
        List<Consumer> consumerList = consumerService.SelectConsumerByVip(vipStatus);
        return Result.success(consumerList);
    }

    //添加消费者信息
    @PostMapping
    public Result insert(@RequestBody Consumer consumer){
        log.info("新增消费者： {},",consumer );
        consumerService.insert(consumer);
        return Result.success();
    }

    //根据id删除消费者信息
    @DeleteMapping
    public Result delete(Integer id){
        log.info("根据id删除消费者信息：{}",id);
        consumerService.delete(id);
        return Result.success();
    }

    //根据name查询信息
    @GetMapping("/{name}")
    public Result select(@PathVariable String name){
        log.info("根据name查询信息 {}",name);
        Consumer con = consumerService.select(name);
        return Result.success(con);
    }

    //查询vip和非会员信息
    @GetMapping
    public Result insertVip(Integer status){
        log.info("查询全部会员信息 {}",status);
        List<Consumer> consumers = consumerService.selectVip(status);
        return Result.success(consumers);
    }

    @DeleteMapping("/{ids}")
    public Result deleteIds(@PathVariable List<Integer> ids){
        log.info("批量删除消费者信息 {}",ids);
        consumerService.deleteIds(ids);
        return Result.success();

    }

    @PutMapping("/update")
    public Result UpdateConsumerById(@RequestBody Consumer consumer){
        consumerService.UpdateConsumerById(consumer);

        return Result.success();

    }
}
